home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / NetSprocketTest / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.6 KB  |  164 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. #        main.c
  4. #
  5. #        This is the main entry point.
  6. #
  7. #        Author(s):     Michael Marinkovich
  8. #                    Apple Developer Technical Support
  9. #                    marink@apple.com
  10. #
  11. #        Modification History: 
  12. #
  13. #            2/10/96        MWM     Initial coding                     
  14. #
  15. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  16. #
  17. #
  18. #        You may incorporate this sample code into your applications without
  19. #        restriction, though the sample code has been provided "AS IS" and the
  20. #        responsibility for its operation is 100% yours.  However, what you are
  21. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  22. #        after having made changes. If you're going to re-distribute the source,
  23. #        we require that you make it clear in the source that the code was
  24. #        descended from Apple Sample Code, but that you've made changes.
  25. #
  26. *************************************************************************************/
  27.  
  28.  
  29. #include <NumberFormatting.h>
  30. #include <Sound.h>
  31. #include <TextUtils.h>
  32. #include <ToolUtils.h>
  33.  
  34. #include "App.h"
  35. #include "Global.h"
  36. #include "Proto.h"
  37.  
  38. #include "NetStuff.h"
  39.  
  40. #include <stdio.h>
  41. #include <sioux.h>
  42.  
  43. //----------------------------------------------------------------------
  44. //
  45. //    main - main entry point of our program
  46. //
  47. //
  48. //----------------------------------------------------------------------
  49.  
  50. void main(void)
  51. {
  52.     OSErr            err;
  53.     short            m = 5;
  54.         
  55.     SIOUXSettings.autocloseonquit = true;
  56.     SIOUXSettings.asktosaveonclose = true;
  57.     SIOUXSettings.initializeTB = false;
  58.     SIOUXSettings.setupmenus = false;
  59.     SIOUXSettings.standalone = false;
  60.  
  61.     MaxApplZone();
  62.     
  63.     for (;m == 0;m--)                 // alloc the master pointers
  64.     {
  65.         MoreMasters();
  66.     }
  67.         
  68.     err = Initialize();
  69.  
  70.     EventLoop();
  71.  
  72.     ShutdownNetworking();
  73.     
  74.     AERemove();    
  75.     ExitToShell();
  76.  
  77. }
  78.  
  79.  
  80. //----------------------------------------------------------------------
  81. //
  82. //    HandleError - basic error notification procedure
  83. //
  84. //
  85. //----------------------------------------------------------------------
  86.  
  87. void HandleError(short errNo,Boolean fatal)
  88. {
  89.     DialogPtr            errDialog;
  90.     short                itemHit;
  91.     short                c;
  92.     Handle                button;
  93.     short                itemType;
  94.     Rect                itemRect;
  95.     StringHandle        errString;
  96.     Str255                numString;
  97.     GrafPtr                oldPort;
  98.     
  99.     GetPort(&oldPort);
  100.     SysBeep(30);
  101.     SetCursor(&qd.arrow);
  102.     
  103.     errDialog = GetNewDialog(rErrorDlg, nil, (WindowPtr) -1);
  104.     if (errDialog != nil) 
  105.     {
  106.         ShowWindow(errDialog);
  107.         SetPort(errDialog);
  108.         
  109.         PenPat(&qd.gray);                                // frame user areas
  110.         for (c = 7;c < 9;c++) 
  111.         {
  112.             GetDialogItem(errDialog,c,&itemType,&button,&itemRect);
  113.             FrameRect(&itemRect);
  114.         }
  115.         PenNormal();
  116.  
  117.         GetDialogItem( errDialog, fatal ? 2 : 1, &itemType, &button, &itemRect );
  118.         HiliteControl( (ControlHandle)button, 255);         //    unhilite appropriate button
  119.         
  120.         SetDialogDefaultItem(errDialog,fatal  ? 1 : 2);
  121.         
  122.         NumToString( errNo, numString );
  123.         if ( errNo < 0 )
  124.             errNo = -errNo + 200;
  125.         errString = GetString( 128 + errNo );
  126.         if ( errString == nil )
  127.                 errString = GetString( 128 );
  128.         HLock((Handle)errString);
  129.         
  130.         ParamText( numString, *errString, nil, nil );
  131.     
  132.         HUnlock((Handle)errString);
  133.         
  134.         ModalDialog( nil, &itemHit );
  135.         
  136.         SetPort( oldPort );
  137.  
  138.         DisposeWindow( errDialog );
  139.     }
  140.     else
  141.         ExitToShell();        // since didn't have mem to open dialog assume the worst
  142.             
  143.     if (fatal) 
  144.         ExitToShell();        //    it's a bad one, get out of here
  145.     
  146. }
  147.  
  148.  
  149. //----------------------------------------------------------------------
  150. //
  151. //    HandleAlert - display alert and then exit to shell
  152. //
  153. //
  154. //----------------------------------------------------------------------
  155.  
  156. void HandleAlert(short alertID)
  157. {
  158.     short            item;
  159.     
  160.     
  161.     item = Alert(alertID,nil);
  162.     ExitToShell();
  163.  
  164. }